package first.servlet;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

import org.apache.log4j.BasicConfigurator;


import first.command.Command;
import first.daodto.DaoImpl;
import first.liter.AbstractLanguage;
import first.liter.BaseLanguage;
import first.liter.Literature;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Field;

public class HelloWorldServlet extends javax.servlet.http.HttpServlet {
    private static final Logger log = Logger.getLogger(HelloWorldServlet.class.getName());

    @Override
    public void init(ServletConfig config) throws ServletException {

        super.init(config);

        BasicConfigurator.configure();

        log.info("init() complete");
    }

    @Override
    public void destroy() {
        super.destroy();
        log.info("destroy() complete");
    }


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.getWriter().write("<html><body>" + System.currentTimeMillis() + "jbhhj" + "</body></html>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BaseLanguage bas = null;
        Literature literature = null;
        
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html; charset=UTF-8");
       
    	String page = null;
    	
		Command command = RequestBuilder.getInstance().getCommand(req);
		
		page = command.execute(req, resp);
		
		getServletContext().getRequestDispatcher(page).forward(req, resp);
        
   }
}

